<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>东单办公系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="media/layui/css/layui.css" media="all">
<script type="text/javascript" src="media/js/jquery.min.js"></script>
</head>
<body>

	<div class="layui-container">
		<table id="tbdata" lay-filter="tbop"></table>
		<script type="text/html" id="barop">
			<a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
		</script>
	</div>
	<script src="media/layui/layui.js"></script>
	<script>
		layui.use('table', function() {
			var table = layui.table;
			table.render({
				id : 'id',
				elem : '#tbdata',
				url : 'OaNew/queryquestionbyno.do' //数据接口
				,
				page : true //开启分页
				,
				minWidth : 20,
				size : 'lg',
				cols : [ [ //表头
                    {type:'checkbox'},
				{
					field : 'qtype',
					align : 'center',
					title : '类型'
				//fixed : 'left'
				}, {
					field : 'question',
					align : 'center',
					title : '问题'
				}, {
					field : 'answer',
					align : 'center',
					title : '答案'
				}, {
					field : 'star',
					align : 'center',
					title : '星评',
					templet : '<div id="{{d.star}}"></div>'

				}, {
					field : 'right',
					title : '操作',
					align : 'center',
					toolbar : "#barop",
					fixed : 'right',
					width : 200
				}
				] ]
			});
			//监听工具条
			table.on('tool(tbop)', function(obj) {
				var data = obj.data;

				console.log(data)

				if (obj.event === 'del') {
						layer.confirm('是否确认删除该行数据?',

								function(index) {
									$.ajax({
										url : "OaNew/questiondelete.do",
										type : "POST",
										data : "id=" + data.id,
										success : function(data) {
											if (data.code == 0) {
												obj.del();//删除表格中的对应行数据
												layer.close(index);
												layer.msg("删除成功", {
													icon : 6
												});
											} else {
												layer.msg("删除失败", {
													icon : 5
												});
											}
										}
									});
								});
					} else if (obj.event === 'edit') {//编辑 修改
						location.href = "questionupdate.html?id=" + data.id;

						}
			});
		});
	</script>

</body>
</html>